<?php

class pagseguroPagamento extends Object implements pagamentoModulo{
    
    private $token  = "";
    private $url    = "";
    
    public function __construct() {
        require_once 'files/config.php';
        $this->token    = PAGSEGURO_TOKEN;
        $this->url      = PAGSEGURO_URL;
        $this->checkout = PAGSEGURO_URL_CHECKOUT;
    }
    
    public function finalizar($itens, $comprador, $compra, $redirect_url){
        
        $var = "<?xml version='1.0' encoding='".CHARSET."' standalone='yes'?>  
        <checkout>  
            <currency>BRL</currency>  
            <items>";
                foreach($itens as $item){
                    extract($item);
                    $preco = number_format($preco, 2, ".", "");
                    $var .= "
                    <item>  
                        <id>$cod_produto</id>  
                        <description>$pnome</description>  
                        <amount>$preco</amount>  
                        <quantity>$qtd</quantity>  
                        <weight>$peso</weight>  
                    </item>";
                }
            extract($comprador);
            $ddd      = substr($telefone, 0, 2);
            $telefone = substr($telefone, 2, 8);
            $var .= "</items>  
            <sender>  
                <name>$nome</name>  
                <email>$email</email>  
                <phone>  
                    <areaCode>$ddd</areaCode>  
                    <number>$telefone</number>  
                </phone>  
            </sender>";
            
            extract($compra);
            $var .="
            <reference>$cod_compra</reference>  
            <shipping>  
                <type>$fretetipo</type>  
                <address>  
                    <street>$rua</street>  
                    <number>$numero</number>  
                    <complement>$complemento</complement>
                    <district>$bairro</district>
                    <postalCode>$cep</postalCode>
                    <city>$cidade</city>
                    <state>$estado</state>
                    <country>BRA</country>
                </address>
            </shipping>
            <redirectURL>$redirect_url</redirectURL>
        </checkout>";
    }
}

?>
